﻿package com.sgcc.nfc.lock.data.repository

import com.sgcc.nfc.lock.core.network.NetworkResult
import com.sgcc.nfc.lock.core.network.safeApiCall
import com.sgcc.nfc.lock.data.remote.api.MapApi
import com.sgcc.nfc.lock.domain.model.MapPoint
import com.sgcc.nfc.lock.domain.repository.MapRepository
import javax.inject.Inject

class MapRepositoryImpl @Inject constructor(
    private val mapApi: MapApi
) : MapRepository {

    override suspend fun getMapRooms(regionId: Long?, status: Int?): NetworkResult<List<MapPoint>> {
        val response = safeApiCall { mapApi.getMapRooms(regionId, status) }
        return when (response) {
            is NetworkResult.Success -> NetworkResult.Success(
                response.data?.mapNotNull { it.toDomain() }.orEmpty()
            )
            is NetworkResult.Error -> response
            NetworkResult.Loading -> NetworkResult.Loading
        }
    }
}

